package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.device.service.DeviceService;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备接口")
@Slf4j
@RestController
@RequestMapping("device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;
    /**
     * 获取场站信息
     * @return
     */
    @ApiOperation("获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult<StationInfoVO> getStationInfo(@PathVariable("gunId") Integer gunId){
        log.info("获取场站信息,参数:{}",gunId);
        StationInfoVO stationInfoVO = deviceService.getStationInfo(gunId);
        JsonResult result = JsonResult.ok(stationInfoVO,"获取场站信息成功");
        log.info("获取场站信息,参数:{},结果:{}",gunId,result);
        return result;
    }

    /**
     * 获取附近充电站
     * @return
     */
    @ApiOperation("附近充电站")
    @GetMapping("/station/near")
    public JsonResult<List<StationInfoVO>> getNearStation(Double longitude,
                                                          Double latitude,
                                                          Double radius){
        log.info("获取附近充电站,经度:{}，纬度:{},距离:{}",longitude,latitude,radius);
        List<StationInfoVO> stationInfoVOS =
                deviceService.getNearStation(longitude,latitude,radius);
        JsonResult result = JsonResult.ok(stationInfoVOS,"获取附近场站信息成功");
        log.info("获取附近充电站,经度:{}，纬度:{},距离:{},结果:{}",
                longitude,latitude,radius,result);
        return result;
    }

    /**
     * 更新枪状态
     */
    @ApiOperation("更新枪状态")
    @PostMapping("/station/gun/status/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.info("更新枪状态,参数:{}",gunStatusUpdateParam);
        Boolean success = deviceService.updateGunStatus(gunStatusUpdateParam);
        JsonResult<Boolean> result = JsonResult.ok(success, "更新成功");
        log.info("更新枪状态,参数:{}，结果:{}",gunStatusUpdateParam,result);
        return result;
    }
}
